import request from "@/utils/request";
const api_name = "/admin/acl/user";
export default {
  getUser(current, pageSize, username = "") {
    return request.get(
      `${api_name}/${current}/${pageSize}?username=${username}`
    );
  },
  // 获取单个用户id
  getById(id) {
    return request.get(`${api_name}/get/${id}`);
  },
  // 添加新用户
  add(user) {
    return request.post(`${api_name}/save`, user);
  },
  // 更新一个后台用户
  update(user) {
    return request.put(`${api_name}/update`, user);
  },
  reqAssignList(id) {
    return request.get(`/admin/acl/user/toAssign/${id}`);
  },
  // 给某个用户分配角色
  setAssigin(userId, roleId) {
    return request.post(
      `admin/acl/user/doAssign?userId=${userId}&roleId=${roleId}`
    );
  },

  // 删除一个用户
  removeById(id) {
    return request.delete(`${api_name}/remove/${id}`);
  },
  // 删除多个用户
  removeUsers() {
    return request.delete(`${api_name}/batchRemove`);
  },
  // 获取角色列表
  reqRoleList(current, pageSize, roleName) {
    return request.get(
      `/admin/acl/role/${current}/${pageSize}?roleName=${roleName}`
    );
  },
  reqAddRole(roleName) {
    return request.post("/admin/acl/role/save", { roleName });
  },
  // 删除角色
  deleteRole(id) {
    return request.delete(`/admin/acl/role/remove/${id}`);
  },
  // 获取树形数据
  reqTreeList(id) {
    return request.get(`/admin/acl/permission/toAssign/${id}`);
  },
  saveTree(id, permissionId) {
    return request.post(
      `/admin/acl/permission/doAssign?roleId=${id}&permissionId=${permissionId}`
    );
  },
  reqSaveRoleName(role) {
    return request.put("/admin/acl/role/update", role);
  },
};
